package com.dmj.sqldsl.executor.visitor;

import com.dmj.sqldsl.executor.exception.DeleteParseException;
import com.dmj.sqldsl.model.DslDelete;
import com.dmj.sqldsl.model.column.SubQueryValueColumn;
import com.dmj.sqldsl.model.table.SubQueryTable;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public class DeleteModelVisitor extends ModelVisitor {

  private final QueryModelVisitor queryModelVisitor;

  public String visit(DslDelete delete) {
    String table = visit(delete.getTable());
    String where = visit(delete.getWhere());
    return String.format("delete from %s%s", table, where);
  }

  @Override
  protected String visit(SubQueryValueColumn column) {
    return queryModelVisitor.visit(column);
  }

  @Override
  protected String visit(SubQueryTable table) {
    throw new DeleteParseException("Unsupported delete sql with sub query table!");
  }
}
